package com.yongan.webService.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yongan.business.entity.Business;
import com.yongan.business.service.BusinessService;
import com.yongan.purchase.dao.PurchaseGoodsDetailsDao;
import com.yongan.purchase.entity.Purchase;
import com.yongan.purchase.entity.PurchaseIn;
import com.yongan.purchase.entity.PurchaseReturn;
import com.yongan.purchase.service.PurchaseInService;
import com.yongan.purchase.service.PurchaseReturnService;
import com.yongan.purchase.service.PurchaseService;
import com.yongan.sales.dao.SalesOrderDetailsDao;
import com.yongan.sales.entity.SalesOrder;
import com.yongan.sales.entity.SalesOut;
import com.yongan.sales.entity.SalesReturn;
import com.yongan.sales.service.SalesOrderService;
import com.yongan.sales.service.SalesOutService;
import com.yongan.sales.service.SalesReturnService;
import com.yongan.warehouse.entity.GoodType;
import com.yongan.warehouse.entity.Goodsinformation;
import com.yongan.warehouse.entity.Warehouse;
import com.yongan.warehouse.service.GoodTypeService;
import com.yongan.warehouse.service.GoodsinformationService;
import com.yongan.warehouse.service.WarehouseService;
import com.yongan.webService.entity.ResultInfo;

/**
 * @author liubo
 *
 */
@Controller
@RequestMapping("/list")
public class GetList {
	/*
	 * 获取货品类别
	 */
	@Autowired
	private GoodTypeService goodtypeService;
	@RequestMapping(value = "/goodtype", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<GoodType>> goodtypeList(Model model,HttpServletRequest request) {
		List<GoodType> goodtypelist = null;
		goodtypelist = goodtypeService.getGoodTypeList(0, 70000);
		if(goodtypelist!=null){
			return new ResultInfo<List<GoodType>>(true, goodtypelist);
		}else{
			return new ResultInfo<List<GoodType>>(false, "noInfo");
		}
	}

	/*
	 * 获取客商
	 */
	@Autowired
	private BusinessService businessService;
	@RequestMapping(value = "/business", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<Business>> businessList(Model model,HttpServletRequest request) {
		List<Business> businessList = null;
		businessList = businessService.getBusinessList(0, 70000, "");
		if(businessList!=null){
			return new ResultInfo<List<Business>>(true, businessList);
		}else{
			return new ResultInfo<List<Business>>(false, "noInfo");
		}
	}
	/*
	 * 获取仓库
	 */
	@Autowired
	private WarehouseService warehouseService;
	@RequestMapping(value = "/warehouse", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<Warehouse>> warehouseList(Model model,HttpServletRequest request) {
		List<Warehouse> warehouseList = null;
		warehouseList = warehouseService.getWarehouseList(0, 70000);
		if(warehouseList!=null){
			return new ResultInfo<List<Warehouse>>(true, warehouseList);
		}else{
			return new ResultInfo<List<Warehouse>>(false, "noInfo");
		}
	}
	/*
	 * 获取货品资料
	 */
	@Autowired
	private GoodsinformationService goodsinformationService;
	@RequestMapping(value = "/goodsinformation", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<Goodsinformation>> goodsinformationList(Model model,HttpServletRequest request) {
		List<Goodsinformation> goodsinformationList = null;
		goodsinformationList = goodsinformationService.getGoodsinformationList(0, 70000);
		if(goodsinformationList!=null){
			return new ResultInfo<List<Goodsinformation>>(true, goodsinformationList);
		}else{
			return new ResultInfo<List<Goodsinformation>>(false, "noInfo");
		}
	}

	/*
	 * 获取采购订货单
	 */
	@Autowired
	private PurchaseService purchaseService;
	@Autowired
	private PurchaseGoodsDetailsDao purchaseGoodsDetailsDao;
	@RequestMapping(value = "/purchase", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<Purchase>> purchaseList(Model model,HttpServletRequest request) {
		List<Purchase> purchaseList = null;
		purchaseList = purchaseService.getPurchaseList(0, 70000);
		if(purchaseList!=null){
			for(Purchase purchase:purchaseList){
				purchase.setDetails(purchaseGoodsDetailsDao.queryAllByTopId(purchase.getPurchaseId()));
			}
			return new ResultInfo<List<Purchase>>(true, purchaseList);
		}else{
			return new ResultInfo<List<Purchase>>(false, "noInfo");
		}
	}

	/*
	 * 获取采购入库单
	 */
	@Autowired
	private PurchaseInService purchaseInService;
	@RequestMapping(value = "/purchasein", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<PurchaseIn>> purchaseInList(Model model,HttpServletRequest request) {
		List<PurchaseIn> purchaseInList = null;
		purchaseInList = purchaseInService.getPurchaseInList(0, 70000);
		if(purchaseInList!=null){
			for(PurchaseIn purchaseIn:purchaseInList){
				purchaseIn.setDetails(purchaseGoodsDetailsDao.queryAllByTopId(purchaseIn.getPurchaseId()));
			}
			return new ResultInfo<List<PurchaseIn>>(true, purchaseInList);
		}else{
			return new ResultInfo<List<PurchaseIn>>(false, "noInfo");
		}
	}
	/*
	 * 获取采购退货单
	 */
	@Autowired
	private PurchaseReturnService purchaseReturnService;
	@RequestMapping(value = "/purchasereturn", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<PurchaseReturn>> purchasereturnList(Model model,HttpServletRequest request) {
		List<PurchaseReturn> purchaseReturnList = null;
		purchaseReturnList = purchaseReturnService.getPurchaseReturnList(0, 70000);
		if(purchaseReturnList!=null){
			for(PurchaseReturn purchaseReturn:purchaseReturnList){
				purchaseReturn.setDetails(purchaseGoodsDetailsDao.queryAllByTopId(purchaseReturn.getPurchaseReturnId()));
			}
			return new ResultInfo<List<PurchaseReturn>>(true, purchaseReturnList);
		}else{
			return new ResultInfo<List<PurchaseReturn>>(false, "noInfo");
		}
	}
	/*
	 * 获取销售订单
	 */
	@Autowired
	private SalesOrderService salesOrderService;
	@Autowired
	private SalesOrderDetailsDao salesOrderDetailsDao;
	@RequestMapping(value = "/salesorder", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<SalesOrder>> salesorderList(Model model,HttpServletRequest request) {
		List<SalesOrder> salesOrderList = null;
		salesOrderList = salesOrderService.getSalesOrderList(0, 70000);
		if(salesOrderList!=null){
			for(SalesOrder salesOrder:salesOrderList){
				salesOrder.setDetails(salesOrderDetailsDao.queryAllByTopId(salesOrder.getSalesOrderId()));
			}
			return new ResultInfo<List<SalesOrder>>(true, salesOrderList);
		}else{
			return new ResultInfo<List<SalesOrder>>(false, "noInfo");
		}
	}
	/*
	 * 获取销售出库订单
	 */
	@Autowired
	private SalesOutService salesOutService;
	@RequestMapping(value = "/salesout", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<SalesOut>>salesOutList(Model model,HttpServletRequest request) {
		List<SalesOut> salesOutList = null;
		salesOutList = salesOutService.getSalesOutList(0, 70000);
		if(salesOutList!=null){
			for(SalesOut salesOut:salesOutList){
				salesOut.setDetails(salesOrderDetailsDao.queryAllByTopId(salesOut.getSalesOutId()));
			}
			return new ResultInfo<List<SalesOut>>(true, salesOutList);
		}else{
			return new ResultInfo<List<SalesOut>>(false, "noInfo");
		}
	}
	/*
	 * 获取销售退货订单
	 */
	@Autowired
	private SalesReturnService salesReturnService;
	@RequestMapping(value = "/salesreturn", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public ResultInfo<List<SalesReturn>>salesReturnList(Model model,HttpServletRequest request) {
		List<SalesReturn> salesReturnList = null;
		salesReturnList = salesReturnService.getSalesReturnList(0, 70000);
		if(salesReturnList!=null){
			for(SalesReturn salesReturn:salesReturnList){
				salesReturn.setDetails(salesOrderDetailsDao.queryAllByTopId(salesReturn.getSalesReturnId()));
			}
			return new ResultInfo<List<SalesReturn>>(true, salesReturnList);
		}else{
			return new ResultInfo<List<SalesReturn>>(false, "noInfo");
		}
	}
}
